package com.lin.missyou.api.v1;

import com.lin.missyou.core.LocalUser;
import com.lin.missyou.core.interceptors.ScopeLevel;
import com.lin.missyou.dto.RegisterDTO;
import com.lin.missyou.dto.SuccessDTO;
import com.lin.missyou.models.User;
import com.lin.missyou.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/wx_info")
    @ScopeLevel
    public SuccessDTO updateUserInfo(@RequestBody Map<String,Object> user) {
        userService.updateUserWxInfo(user);
        return new SuccessDTO();
    }

    @GetMapping("/info")
    @ScopeLevel
    public User getUserInfo() {
        return userService.getUserById(LocalUser.getUser().getId());
    }

    @PostMapping("/register_info")
    @ScopeLevel
    public SuccessDTO registerUserInfo(@RequestBody RegisterDTO registerInfo) {
        userService.registerUserInfo(registerInfo);
        return new SuccessDTO();
    }
}